package br.com.lucasddaniel.inbuzios.activities;

import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import br.com.lucasddaniel.inbuzios.Controller;
import br.com.lucasddaniel.inbuzios.R;
import br.com.lucasddaniel.inbuzios.adapter.TuristasAdapter;
import br.com.lucasddaniel.inbuzios.bean.TuristaBean;
import br.com.lucasddaniel.inbuzios.dao.ExcessaoBanco;

public class ListarTuristasActivity extends Activity implements
		OnClickListener {

	// private EditText m_edittext_search;
	private ListView m_listview_turistas;
	private TuristasAdapter m_adapter_turistas;
	private List<TuristaBean> listTurista;

	@Override
	public void onCreate( Bundle savedInstanceState ) {
		super.onCreate( savedInstanceState );
		setContentView( R.layout.activity_listar_turistas );
	}

	private void initComponents() {
		// m_edittext_search = ( EditText ) findViewById( R.id_activity_listar_turistas.edttext_search );
		m_listview_turistas = ( ListView ) findViewById( R.id_activity_listar_turistas.listview );

		m_adapter_turistas = new TuristasAdapter( ListarTuristasActivity.this,
				R.layout.row_turistas, listTurista );
		m_listview_turistas.setAdapter( m_adapter_turistas );
		m_listview_turistas.setOnItemClickListener( new OnItemClickListener() {

			public void onItemClick( AdapterView<?> arg0, View arg1, int posicao,
					long arg3 ) {
				Intent it = new Intent( getApplicationContext(), TuristasActivity.class );
				it.putExtra( "idTurista", listTurista.get( posicao ).getId() );
				startActivity( it );
				//finish();
			}
		} );

//		( ( Button ) findViewById( R.id_activity_listar_turistas.btn_cadastrar ) )
//				.setOnClickListener( this );
	}

	public void onClick( View v ) {
//		switch( v.getId() ) {
//			case R.id_activity_listar_turistas.btn_cadastrar:
//				Intent intent = new Intent( this, TuristasActivity.class );
//				startActivity( intent );
//				break;
//		}
	}

	@Override
	protected void onResume() {
		super.onResume();
		try {
			listTurista = Controller.getInstance().listaTuristas( getApplicationContext() );
		} catch( ExcessaoBanco e ) {
			e.printStackTrace();
		}
		initComponents();
	}
}
